package com.example.zg.androidnewview.utils;

import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.ViewCompat;
import android.util.Log;
import android.view.View;

/**
 * 创建日期:2019/1/9 on 15:21
 * 描述：
 * 作者: zhougan
 */
public class ScrollBehavior1 extends FloatingActionButton.Behavior{
    private static final String TAG = "ScrollBehavior1";

    @Override
    public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull FloatingActionButton child, @NonNull View directTargetChild, @NonNull View target, int axes, int type) {
        return axes == ViewCompat.SCROLL_AXIS_VERTICAL ||
                super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, axes, type);


    }

    @Override
    public void onNestedPreScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull FloatingActionButton child, @NonNull View target, int dx, int dy, @NonNull int[] consumed, int type) {
        super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
        Log.i(TAG, "onNestedPreScroll: ");
        if (dy >= 0 && child.getVisibility() == View.VISIBLE) {
            child.hide();
        } else if (dy < 0 && child.getVisibility() != View.VISIBLE) {
            child.show();
        }


    }

}
